package com.ad.admin.myview;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import com.ad.admin.defviewdemo.R;


/**
 * Created by Administrator on 2016/4/19.
 */
public class MyView extends View {

    public MyView(Context context) {
        super(context);
    }

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //用来清除界面上的内容
        super.onDraw(canvas);

        Paint paint = new Paint();
        paint.setColor(Color.GREEN);
        paint.setTextSize(20);
        //界面中加入文字
        canvas.drawText("这是一段文字", 100, 200, paint);

        paint.setColor(Color.BLUE);
        //加入线
        canvas.drawLine(150,50,200,180,paint);

        paint.setColor(Color.RED);
        paint.setStyle(Paint.Style.FILL);
        //绘制图形
        canvas.drawRect(50,400,500,200, paint);

        //加入图片
        canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.image_file), 120,550,paint);

    }
}
